package order

import (
	"context"
	"group-buy/group_buy/internal/models"

	"group-buy/group_buy/internal/svc"
	"group-buy/group_buy/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderGetOneLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderGetOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderGetOneLogic {
	return &OrderGetOneLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderGetOneLogic) OrderGetOne(req *types.OrderGetOneReq) (resp *types.Order, err error) {
	order := &models.Order{Id: req.Id}
	_, err = l.svcCtx.Engine.Get(order)
	if err != nil {
		return nil, err
	}
	statusStr := ""
	switch order.Status {
	case 1:
		statusStr = "未支付"
	case 2:
		statusStr = "已支付"
	case 3:
		statusStr = "待核销"
	case 4:
		statusStr = "已完成"
	}
	return &types.Order{
		Id:            order.Id,
		Code:          order.Code,
		UserId:        order.UserId,
		ProductId:     order.ProductId,
		Amount:        order.Amount,
		UserName:      order.UserName,
		ProductName:   order.ProductName,
		WriteOffCount: order.WriteOffCount,
		FinishCount:   order.FinishCount,
		Status:        order.Status,
		PayOrderId:    order.PayOrderId,
		OpenId:        order.OpenId,
		InviteId:      order.InviteId,
		ProductCover:  order.ProductCover,
		StatusStr:     statusStr,
		PayTime:       order.PayTime,
	}, nil
}
